<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>

    let str = '1231231asdafasdfas123sdf123';

    let result = str.split('').reduce((a, b) => {
      return (a[b]++ || (a[b] = 1), a)
    }, {})

    console.log(result)
  </script>
</body>
</html>